package com.yaorange.web.controller.nongjt;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yaorange.common.annotation.Log;
import com.yaorange.common.core.controller.BaseController;
import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.common.enums.BusinessType;
import com.yaorange.nongjt.domain.NjtCertificate;
import com.yaorange.nongjt.service.INjtCertificateService;
import com.yaorange.common.utils.poi.ExcelUtil;
import com.yaorange.common.core.page.TableDataInfo;

/**
 * 合格证Controller
 *
 * @author hzliu
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/nongjt/certificate")
public class NjtCertificateController extends BaseController
{
    @Autowired
    private INjtCertificateService njtCertificateService;

    /**
     * 查询合格证列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjtCertificate njtCertificate) {
        startPage();
        List<NjtCertificate> list = njtCertificateService.selectNjtCertificateList(njtCertificate);
        return getDataTable(list);
    }

    /**
     * 导出合格证列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:export')")
    @Log(title = "合格证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjtCertificate njtCertificate)
    {
        List<NjtCertificate> list = njtCertificateService.selectNjtCertificateList(njtCertificate);
        ExcelUtil<NjtCertificate> util = new ExcelUtil<NjtCertificate>(NjtCertificate.class);
        util.exportExcel(response, list, "合格证数据");
    }

    /**
     * 获取合格证详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        NjtCertificate certificate = njtCertificateService.selectNjtCertificateById(id);
        return success(certificate);
    }

    /**
     * 新增合格证
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:add')")
    @Log(title = "合格证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NjtCertificate njtCertificate)
    {
        return toAjax(njtCertificateService.insertNjtCertificate(njtCertificate));
    }

    /**
     * 修改合格证
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:edit')")
    @Log(title = "合格证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NjtCertificate njtCertificate)
    {
        return toAjax(njtCertificateService.updateNjtCertificate(njtCertificate));
    }

    /**
     * 删除合格证
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certificate:remove')")
    @Log(title = "合格证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(njtCertificateService.deleteNjtCertificateByIds(ids));
    }
}
